package com.ruoyi.plus.pub.api;

import com.ruoyi.common.core.api.ApiResult;
import com.ruoyi.common.core.api.BaseApi;
import com.ruoyi.common.core.api.version.ApiVersion;
import com.ruoyi.plus.constants.PlusDictConstants;
import com.ruoyi.plus.pub.api.vo.PubConfigPlusVo;
import com.ruoyi.plus.pub.domain.PubConfigPlus;
import com.ruoyi.plus.pub.service.IPubConfigPlusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置Api
 *
 */
@Slf4j
@Api(tags = "PubConfigPlusApi-系统配置")
@ApiVersion()
@RestController
@RequestMapping(value = {"app/api/pub/pubConfigPlusApi"})
public class PubConfigPlusApi extends BaseApi {

    @Autowired
    private IPubConfigPlusService configPlusService;

    /**
     * 获取系统配置对象
     */
    @ApiOperation("getConfig-获取系统配置对象")
    @GetMapping("/getConfig")
    @ResponseBody
    public ApiResult<PubConfigPlusVo> getConfig(@RequestParam("code") String code) {
        PubConfigPlus entity = configPlusService.findByConfigKey(code.trim());
        if (null == entity) {
            return new ApiResult<PubConfigPlusVo>().setCode(-1).setMsg("您所查询的code{" + code + "}不存在!").setData(null).setApiVersion(this.getApiVersion());
        }
        if (!PlusDictConstants.SYS_NORMAL_DISABLE_NORMAL.equals(entity.getStatus())) {
            return new ApiResult<PubConfigPlusVo>().setCode(0).setMsg("您所查询的code{" + code + "}状态已停用!").setData(null).setApiVersion(this.getApiVersion());
        }
        PubConfigPlusVo vo = new PubConfigPlusVo();
        BeanUtils.copyProperties(entity, vo);
        return new ApiResult<PubConfigPlusVo>(getApiVersion()).setData(vo).setApiVersion(this.getApiVersion());
    }


}
